/* eslint-disable */
import path, { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
export default ({ command, mode }) => {
  return {
    plugins: [
      vue(),
      vueJsx(),
    ],
    build: {
      outDir: 'lib',
      lib: {
        entry: path.resolve(__dirname, './src/package/index.js'),
        name: 'bpmn-viewer',
        fileName: 'bpmn-viewer',
        formats: ['es', 'umd'],
      },
      rollupOptions: {
        external: ['vue','element-plus', '@element-plus/icons-vue','axios'],
        output: {
          globals: {
            vue: 'Vue',
            'element-plus': 'ElementPlus'
          },
        },
      },
    },
    resolve: {
      alias: {
        '~': resolve(__dirname, './'),
        '@': resolve(__dirname, 'src'),
        'src': resolve(__dirname, 'src')
      },
      extensions: ['.js', '.ts', '.tsx', '.json', '.vue']
    },
    css: {
      // css sass  charset 报错
      postcss: {
        plugins: [
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset: (atRule) => {
                if (atRule.name === 'charset') {
                  atRule.remove();
                }
              }
            }
          }
        ],
      }
    },
    optimizeDeps: {
      include: ['element-plus/es/locale/lang/zh-cn',
        'bpmn-js/lib/Modeler',
        'bpmn-js-token-simulation'
      ]
    }
  }
}
